package com.mpb.prj.practice;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;

import org.xml.sax.SAXException;

public class JPLMain {

	public static void main(String[] args) throws SAXException, IOException,
			ParserConfigurationException, TransformerException {
		Properties properties = new Properties();
		properties.load(new FileInputStream(args[0]));
		JPLMain object = new JPLMain();
		object.executeXTandem(properties);
		object.calculateFDR(properties);
		
	}

	private void executeXTandem(Properties properties) throws SAXException,
			IOException, ParserConfigurationException, TransformerException {
		JPLGenerateXml input = new JPLGenerateXml();
		input.setDataFolderPath(properties.getProperty("DATA_FOLDER"));
		input.setXtandemFolderPath(properties.getProperty("XTANDEM_FOLDER"));
		input.generateXtandemInputXml(properties.getProperty("TAXONOMY_FILE"),
				properties.getProperty("DEFAULT_INPUT_FILE"), properties
						.getProperty("SPECTRA_FILE"));
		
		JPLRunXTandemBatchMain obj1 = new JPLRunXTandemBatchMain();
		obj1.runXTandem(properties.getProperty("XTANDEM_FOLDER"), properties
				.getProperty("DATA_FOLDER")
				+ "/new_input.xml", properties.getProperty("INPUT_FOLDER"),
				properties.getProperty("INPUT_REGEX"), properties
						.getProperty("OUTPUT_FOLDER"));
	}

	private void calculateFDR(Properties properties) {
		JPLFDRCalculation outFile = new JPLFDRCalculation();
		outFile.calculateFDR(properties.getProperty("OUTPUT_FOLDER"),
				properties.getProperty("OUTPUT_REGEX"),properties
				.getProperty("DATA_FOLDER")
				+ "/new_input.xml");
	}
}